import os

import xlrd
from config.config import DATAS_PATH

def read_crm_goods(index,file_name):
    """读取excle文件数据，返回字典组成的列表"""
    data = xlrd.open_workbook(file_name)  # 打开excel表文件
    table = data.sheet_by_index(index)  # 打开表格页
    keys = table.row_values(0)  # 获取第一行
    lst = []
    lines = table.nrows - 1
    for i in range(lines):
        values = table.row_values(i + 1)
        lst.append(dict(zip(keys, values)))
    return lst

if __name__ == '__main__':
    data = read_crm_goods(0,os.path.join(DATAS_PATH,'crm_goods.xls'))
    print(data)
